<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
<style>
*{margin: 0px;padding: 0px}
.box{width:200px;height:200px;background-color:pink;position: absolute}
.line{width: 2px;height: 100%;position: absolute;left:1000px;background-color: black;}




</style>
</head>
<body>
        <input type="button" value="开始" id="btn">
        <div class="box"></div>
        <div class="line"></div>
</body>
<script>
function $(ele){
        return document.querySelector(ele);
    }

    let timer = null;
    let speed = 0;
    $('#btn').onclick = function(){
       // setItnerval(function(){} , ()=>{})
        timer = setInterval(() => {
            // 10/50  = 0.2px
            speed = (1000-$('.box').offsetLeft)/50;
            speed = speed<1?Math.ceil(speed):speed;
            if($('.box').offsetLeft>=1000){
                clearInterval(timer)
            }else{
                $('.box').style.left = $('.box').offsetLeft+ speed +'px';
            }
        }, 20);
    }

</script>
</html>